import store from "../../store/store";
import {Router,Route,hashHistory,IndexRedirect} from "react-router";
var Xx = React.createClass({
	render : function(){
		return (
			<div className="xx_car" data-id={this.props.data.id}>
				<img  src={this.props.data.img}/>
				<section>
					<p>{this.props.data.conent}</p>
					<h3>
						<b>¥{this.props.data.pric}</b>
						<span>库存:{this.props.data.num}</span>
					</h3>
				</section>
			</div>
		)
	}
})



export default React.createClass({
	mo:function(){
		$(".car_goods_bom").animate({bottom:"-4rem"},500,function(){
			$(".zhegai").css({display:"none"})
		})
	},
	jia:function(){
		var  ls = $(".carnum").html()
		$(".carnum").html(Number(ls)+1)
	},
	jian:function(){
		var  ls = $(".carnum").html()
		if(ls>1){
			$(".carnum").html(Number(ls)-1)
		}
	},
	btn:function(){
		var num = $(".carnum").html()
		var obj = {
			type:"ADD_CAR",
			goods :{
				id :this.props.data.id,
				num:num,
				price:this.props.data.pric,
				img:this.props.data.img,
				conent:this.props.data.conent
			}
		}
		store.dispatch(obj)
	},
	render :function(){
		return (
			<div className="car_goods_bom">
				<div className = "xiaoshi_car_wai">
					<span className="xiaoshi_car" onClick={this.mo}>X</span>
				</div>
				<Xx data={this.props.data}/>
				<div className="car_cao">
					<span>购买数量 : </span>
					<section>
						<aside onClick={this.jian}>-</aside>
						<aside className="carnum">1</aside>
						<aside onClick={this.jia}>+</aside>
					</section>
				</div>
				<div className="car_bom_btn">
					<button onClick = {this.btn}>加入购物车</button>
					<button onClick = {this.btn}>立即购买</button>
				</div>
			</div>
		)
	}
})
